﻿namespace Main.lib.space
{

    /**
     * Four-dimensional space class
     * 
     * @author  Bruno Miguel de Oliveira Tamer <bmotamer@gmail.com>
     * @version 2011.11.25
     * 
     * @brief   Let you create a "lightweight" four-dimensional array
     * @param   Generic container type
     */
    public sealed class Tesseract<T>
    {

        public readonly uint Width, Height, Depth, Diagonal; // Dimensions
        public readonly T[]  Data;                           // Container

        /**
         * Constructor
         * 
         * @brief Creates the container
         * @param Width
         * @param Height
         * @param Depth
         * @param Diagonal
         */
        public Tesseract(uint width, uint height, uint depth, uint diagonal)
        {
            Width    = width;
            Height   = height;
            Depth    = depth;
            Diagonal = diagonal;
            Data     = new T[Diagonal * Depth * Height * Width];
        }

        /**
         * Container accessor
         * 
         * @brief Let you get or set a position's value
         * @param X-coordinate
         * @param Y-coordinate
         * @param Z-coordinate
         * @param W-coordinate
         */
        public T this[uint x, uint y, uint z, uint w]
        {
            get
            {
                return Data[x + (y + (z + w * Depth) * Height) * Width];
            }
            set
            {
                Data[x + (y + (z + w * Depth) * Height) * Width] = value;
            }
        }

    }

}